package com.zq.assistant.func.ioc.finder.view;

import android.view.View;

import com.zq.assistant.func.ioc.finder.cache.FindCache;

/**
 * Created by zhangqiang on 17-7-11.
 */

public class CachedViewFinder implements ViewFinder {

    private FindCache<Integer,View> findCache;
    private ViewFinder viewFinder;

    public CachedViewFinder(FindCache<Integer,View> findCache, ViewFinder viewFinder) {
        this.findCache = findCache;
        this.viewFinder = viewFinder;
    }

    @Override
    public View findViewById(int viewId) {

        if(findCache != null){

            View view = findCache.get(viewId);
            if(view != null){
                return view;
            }
        }

        View view = viewFinder.findViewById(viewId);
        if(view != null && findCache != null){

            findCache.put(viewId,view);
        }
        return view;
    }
}
